const formatDate = function(data,temp='yyyy-MM-dd HH:mm:ss'){
    let d = new Date( data );
    if(d=="Invalid Date"){
        console.warn(data+":不是一个可以转换为时间的有效数据");
        return data;
    }
    let opt = {
        "y+":String(d.getFullYear()),
        "M+":String(d.getMonth()+1),
        "d+":String(d.getDate()),
        "H+":String(d.getHours()),
        "m+":String(d.getMinutes()),
        "s+":String(d.getSeconds())
    }

    for (let k in opt) {
        let reg = new RegExp(k);
        let arr = temp.match(reg);
        if(arr){
            let leg = arr[0].length;
            temp = temp.replace(reg, opt[k].padStart(leg,"0") )
        }
    }
    return temp;
}

export default {
    install(Vue){
        Vue.prototype.$util = {
            formatDate
        }
    }
}